package com.mrtan.service.impl;

import com.mrtan.bean.Customer;
import com.mrtan.mapper.CustomerMapper;
import com.mrtan.service.CustomerService;
import com.mrtan.vo.CustomerVO;
import com.mrtan.vo.CustomerWhereVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerMapper customerMapper;

    @Override
    public List<String> selectNames() {
        List<String> names = customerMapper.selectNames();
        return names;
    }

    @Override
    public List<Customer> selectAll(CustomerWhereVO customerWhereVO) {
        List<Customer> customers = customerMapper.selectAll(customerWhereVO);
        return customers;
    }

    @Override
    public int insertSelective(CustomerVO CustomerVO) {
        //去重
        Customer customer = customerMapper.selectByEmail(CustomerVO.getEmail());
        if(customer!=null){
            return -1;
        }
        int i = customerMapper.insertSelective(CustomerVO);
        return i;
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return customerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(CustomerVO CustomerVO) {
        return customerMapper.updateByPrimaryKeySelective(CustomerVO);
    }

    @Override
    public int selectOrderCount(String customerName) {
        return customerMapper.selectOrderCount(customerName);
    }

    @Override
    public List<Map<Customer,Integer>> getCustomerOrderSum(Integer month) {
        List<Map<Customer, Integer>> customerOrderSum = customerMapper.getCustomerOrderSum(month);
        return customerOrderSum;
    }

    @Override
    public List<Map<String, Object>> selectTotalAmountByCustomerAndTime(Integer month) {
        List<Map<String, Object>> maps = customerMapper.selectTotalAmountByCustomerAndTime(month);
        return maps;
    }

    @Override
    public List<Map<String, Object>> selectTotalorderByCustomerTime() {
        return customerMapper.selectTotalorderByCustomerTime();
    }
}
